#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-06-19 23:21:22
# @Author  : shitao.tommy (hero007asd@gmail.com)
# @Link    : http://example.org
# @Version : $Id$
from lib import libtime
import os


def findfiles(dirname,pattern):
     cwd = os.getcwd() #保存当前工作目录
     if dirname:
         os.chdir(dirname)
  
     result = []
     for filename in glob.iglob(pattern): #此处可以用glob.glob(pattern) 返回所有结果
         result.append(filename)
     #恢复工作目录
     os.chdir(cwd)
     return result


def find_subclasses(klass, include_self=False):
    accum = []
    for child in klass.__subclasses__():
        accum.extend(find_subclasses(child, True))
    if include_self:
        accum.append(klass)
    return accum

def _not_exist_create_folder(ori_path):
    '''如果不存在创建文件夹'''
    year, month, day = libtime.get_date()
    path = ori_path + '/' + str(year) + '/' + str(month) + '/' + str(day)
    if not os.path.isdir(path):
        os.makedirs(path)
    return path

def _exist_remove_folder():
    '''如果存在删除文件夹'''
    pass

def _not_exist_create_file():
    '''如果不存在创建文件'''
    pass

def _exist_remove_file():
    '''如果存在删除文件'''
    pass

def new_img(path, imgname):
    '''获取新建图片的路径'''
    return _not_exist_create_folder(path) + '/' + imgname

    